package com.spic.business.informatization.meeting.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spic.business.informatization.meeting.domain.MeetingActivityFile;
import com.spic.business.informatization.meeting.mapper.MeetingActivityFileMapper;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 应急预案附件Controller
 *
 * @author spic
 * @date 2021-11-01
 */
@RestController
@RequestMapping("/informatization/meeting")
public class MeetingActivityFileController extends BaseController
{
    @Autowired
    private MeetingActivityFileMapper fileMapper;

    /**
     * 查询应急预案附件列表
     */
    @GetMapping("/file/list")
    public TableDataInfo list(MeetingActivityFile file)
    {
        startPage();
        List<MeetingActivityFile> list = fileMapper.selectList(
                new LambdaQueryWrapper<MeetingActivityFile>()
                    .eq(MeetingActivityFile::getMeetingActivityId, file.getMeetingActivityId())
        );
        return getDataTable(list);
    }


    /**
     * 新增应急预案附件
     */
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping("/file")
    public AjaxResult add(@RequestBody MeetingActivityFile file)
    {
        return toAjax(fileMapper.insert(file));
    }

    /**
     * 修改应急预案附件
     */
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PutMapping("/file")
    public AjaxResult edit(@RequestBody MeetingActivityFile file)
    {
        return toAjax(fileMapper.updateById(file));
    }

    /**
     * 删除应急预案附件
     */
    @Log(title = "附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/files/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(fileMapper.deleteById(id));
    }
}
